class Calculator:
    def add(self, x, y):
        """加法运算"""
        return x + y

    def subtract(self, x, y):
        """减法运算"""
        return x - y

    def multiply(self, x, y):
        """乘法运算"""
        return x * y

    def divide(self, x, y):
        """除法运算"""
        if y == 0:
            raise ValueError("除数不能为零！")
        return x / y


def main():
    calc = Calculator()

    while True:
        print("\n简单计算器")
        print("1. 加法")
        print("2. 减法")
        print("3. 乘法")
        print("4. 除法")
        print("5. 退出")

        choice = input("请选择操作 (1-5): ")

        if choice == '5':
            print("感谢使用！再见！")
            break

        if choice not in ('1', '2', '3', '4'):
            print("无效的选择，请重试。")
            continue

        try:
            num1 = float(input("请输入第一个数字: "))
            num2 = float(input("请输入第二个数字: "))
        except ValueError:
            print("输入无效，请输入数字！")
            continue

        if choice == '1':
            print(f"结果: {calc.add(num1, num2)}")
        elif choice == '2':
            print(f"结果: {calc.subtract(num1, num2)}")
        elif choice == '3':
            print(f"结果: {calc.multiply(num1, num2)}")
        elif choice == '4':
            try:
                print(f"结果: {calc.divide(num1, num2)}")
            except ValueError as e:
                print(f"错误: {e}")


if __name__ == "__main__":
    main()
